{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np  #矩阵操作\n",
    "import pandas as pd #数据处理\n",
    "from sklearn.metrics import r2_score #评价回归模型性能\n",
    "import matplotlib.pyplot as plt #画图\n",
    "import seaborn as sns\n",
    "#图形出现在notebook里边而不是新窗口\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CRIM</th>\n",
       "      <th>ZN</th>\n",
       "      <th>INDUS</th>\n",
       "      <th>CHAS</th>\n",
       "      <th>NOX</th>\n",
       "      <th>RM</th>\n",
       "      <th>AGE</th>\n",
       "      <th>DIS</th>\n",
       "      <th>TAX</th>\n",
       "      <th>PTRATIO</th>\n",
       "      <th>...</th>\n",
       "      <th>RAD_2</th>\n",
       "      <th>RAD_3</th>\n",
       "      <th>RAD_4</th>\n",
       "      <th>RAD_5</th>\n",
       "      <th>RAD_6</th>\n",
       "      <th>RAD_7</th>\n",
       "      <th>RAD_8</th>\n",
       "      <th>RAD_24</th>\n",
       "      <th>MEDV</th>\n",
       "      <th>log_MEDV</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.18</td>\n",
       "      <td>0.067815</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.314815</td>\n",
       "      <td>0.577505</td>\n",
       "      <td>0.641607</td>\n",
       "      <td>0.269203</td>\n",
       "      <td>0.208015</td>\n",
       "      <td>0.287234</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.422222</td>\n",
       "      <td>0.666856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.547998</td>\n",
       "      <td>0.782698</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.553191</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.368889</td>\n",
       "      <td>0.619696</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000236</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.242302</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.172840</td>\n",
       "      <td>0.694386</td>\n",
       "      <td>0.599382</td>\n",
       "      <td>0.348962</td>\n",
       "      <td>0.104962</td>\n",
       "      <td>0.553191</td>\n",
       "      <td>...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.660000</td>\n",
       "      <td>0.833335</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000293</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.658555</td>\n",
       "      <td>0.441813</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.648936</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.631111</td>\n",
       "      <td>0.816001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.000705</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.063050</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.150206</td>\n",
       "      <td>0.687105</td>\n",
       "      <td>0.528321</td>\n",
       "      <td>0.448545</td>\n",
       "      <td>0.066794</td>\n",
       "      <td>0.648936</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.693333</td>\n",
       "      <td>0.852567</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 22 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       CRIM   ZN     INDUS   CHAS       NOX        RM       AGE       DIS  \\\n",
       "0  0.000000  0.18  0.067815   0.0  0.314815  0.577505  0.641607  0.269203   \n",
       "1  0.000236  0.00  0.242302   0.0  0.172840  0.547998  0.782698  0.348962   \n",
       "2  0.000236  0.00  0.242302   0.0  0.172840  0.694386  0.599382  0.348962   \n",
       "3  0.000293  0.00  0.063050   0.0  0.150206  0.658555  0.441813  0.448545   \n",
       "4  0.000705  0.00  0.063050   0.0  0.150206  0.687105  0.528321  0.448545   \n",
       "\n",
       "        TAX   PTRATIO  ...  RAD_2  RAD_3  RAD_4  RAD_5  RAD_6  RAD_7  RAD_8  \\\n",
       "0  0.208015  0.287234  ...      0      0      0      0      0      0      0   \n",
       "1  0.104962  0.553191  ...      1      0      0      0      0      0      0   \n",
       "2  0.104962  0.553191  ...      1      0      0      0      0      0      0   \n",
       "3  0.066794  0.648936  ...      0      1      0      0      0      0      0   \n",
       "4  0.066794  0.648936  ...      0      1      0      0      0      0      0   \n",
       "\n",
       "   RAD_24      MEDV  log_MEDV  \n",
       "0       0  0.422222  0.666856  \n",
       "1       0  0.368889  0.619696  \n",
       "2       0  0.660000  0.833335  \n",
       "3       0  0.631111  0.816001  \n",
       "4       0  0.693333  0.852567  \n",
       "\n",
       "[5 rows x 22 columns]"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# df = pd.read_csv('FE_boston.csv')\n",
    "df = pd.read_csv('FE_MinMax_boston.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Index(['CRIM', ' ZN ', 'INDUS ', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS', 'TAX',\n",
      "       'PTRATIO', 'LSTAT', 'RAD_1', 'RAD_2', 'RAD_3', 'RAD_4', 'RAD_5',\n",
      "       'RAD_6', 'RAD_7', 'RAD_8', 'RAD_24'],\n",
      "      dtype='object')\n"
     ]
    }
   ],
   "source": [
    "y = df['MEDV']\n",
    "x = df.drop(['MEDV','log_MEDV'],axis = 1)\n",
    "feat_names = x.columns\n",
    "print(feat_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(404, 20)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分离除部分数据用来测试\n",
    "from sklearn.model_selection import train_test_split\n",
    "#使用20%的数据作为测试\n",
    "x_train,x_test,y_train,y_test = train_test_split(x,y,random_state = 33,test_size = 0.2)\n",
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "#使用线性回归训练模型获取结果\n",
    "lr = LinearRegression()\n",
    "lr.fit(x_train,y_train)\n",
    "y_test_pre = lr.predict(x_test)\n",
    "y_train_pre = lr.predict(x_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>RM</td>\n",
       "      <td>0.437204</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ZN</td>\n",
       "      <td>0.122593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.094125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.065403</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.034324</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.033908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030563</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.012456</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.003638</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008870</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011838</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040752</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.051096</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.080363</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.110471</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.166505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.188093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.245829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.383894</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.497139</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns      coef\n",
       "5        RM  0.437204\n",
       "1       ZN   0.122593\n",
       "19   RAD_24  0.094125\n",
       "3      CHAS  0.065403\n",
       "13    RAD_3  0.034324\n",
       "17    RAD_7  0.033908\n",
       "18    RAD_8  0.030563\n",
       "2    INDUS   0.012456\n",
       "6       AGE  0.003638\n",
       "14    RAD_4 -0.008870\n",
       "15    RAD_5 -0.011838\n",
       "12    RAD_2 -0.040752\n",
       "16    RAD_6 -0.051096\n",
       "11    RAD_1 -0.080363\n",
       "8       TAX -0.110471\n",
       "4       NOX -0.166505\n",
       "9   PTRATIO -0.188093\n",
       "0      CRIM -0.245829\n",
       "7       DIS -0.383894\n",
       "10    LSTAT -0.497139"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#看各个特征的权重系数\n",
    "fs = pd.DataFrame({\"columns\":list(feat_names),\"coef\":list((lr.coef_.T))})\n",
    "fs.sort_values(by = ['coef'],ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r2 test 0.6817328674380889\n",
      "r2 train 0.7514111562219241\n"
     ]
    }
   ],
   "source": [
    "#使用r2_score评估测试和训练的性能\n",
    "print('r2 test',r2_score(y_test,y_test_pre))\n",
    "print('r2 train', r2_score(y_train,y_train_pre))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0x1a1892df50>"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAewAAAFsCAYAAAAOmoq4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2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Do48+yqRJk7j44ou7Zf/r1q3rlv1cf/31vSqsoc7AjoilEfHriFgQEfOqdcMi4r6IWFzdDm1sqZKkRpsxYwZf//rXAZg0aRLTp09n/Pjx7L333jzwwAMAvP7665x77rkcfPDBjBkzhu985zsArF69msMPP5yDDjqI0aNHc9dddwGwdOlS9t13Xz796U9z0EEH8dRTT230mocccghPP/30huVbbrmF8ePHM3bsWD75yU/y+uuvA3DDDTew9957M2nSJD7xiU9w5plnAjBt2jTOOeccDjvsMKZPn86aNWs49dRTOfjggznwwAM31LFw4cIN+x0zZgyLFy9mzZo1fPCDH+SAAw5g//33Z+bMmRvavv5S2rfeeiujR49m//33Z/r06RvqHDx4MF/60pc44IADmDhxIs8880z3HoxNbE0P+7DMHJuZ46rl84DZmbkXMLtaliT1IevWreOhhx7iiiuu4Mtf/jJQC84ddtiBuXPnMnfuXK677jqeeOIJBg0axB133MGvfvUr5syZw+c//3nWf4Xz7373O0455RQefvjhNw1933vvvRx77LEALFq0iJkzZ/Lzn/+cBQsWMGDAAL73ve+xfPlyvvKVr/Dggw9y33338dhjj220j8cff5xZs2bxjW98g69+9atMnjyZuXPnMmfOHM4991zWrFnDNddcw1lnncWCBQuYN28eo0aN4t5772XXXXflkUce4Te/+Q1HH330Rvtdvnw506dP5yc/+QkLFixg7ty53HnnnQCsWbOGiRMn8sgjj/C+972P6667riHHYL2uDIlPAW6q7t8EHNv1ciRJvclHPvIRAN773veydOlSAH784x9z8803M3bsWCZMmMCqVatYvHgxmcn555/PmDFjOOKII3j66ac39Dp33313Jk6cuNG+DzvsMEaMGMGsWbP42Mc+BsDs2bOZP38+Bx98MGPHjmX27NksWbKEhx56iEMPPZRhw4bR0tLCCSecsNG+TjjhBAYMGLChvksvvZSxY8cyadIk1q5dyx//+EcOOeQQvva1r3HZZZfx5JNPst122zF69GhmzZrF9OnTeeCBB9hhhx022u/cuXOZNGkSw4cPZ+DAgZx88sn89Kc/BWDbbbflQx/60Jt+P41S76SzBH4cEQl8JzOvBXbJzBUAmbkiIkY0qkhJUnO85S1vAWDAgAEbzg9nJldeeSVHHXXURtveeOONrFy5kvnz59PS0kJra+uGzyFvv/32b9r3nDlz2H777Zk2bRoXXXQRl19+OZnJ1KlTueSSSzba9o477thinW33n5ncfvvtvOc979lom3333ZcJEybwwx/+kKOOOorrr7+eyZMnM3/+fH70ox/xxS9+kSOPPJKLLrpoo31tTktLy4aPbrX9/TRKvYH9N5m5vArl+yLisQ6fUYmIM4AzAN75znd2okT1ZVszM7a7Z9FK6pyjjjqKq6++msmTJ9PS0sLjjz/ObrvtxksvvcSIESNoaWlhzpw5PPlkx98iud1223HFFVcwevRoLrjgAg4//HCmTJnC2WefzYgRI3j++ed55ZVXGD9+PGeffTYvvPACQ4YM4fbbb2f06NGbre/KK6/kyiuvJCJ4+OGHOfDAA1myZAl77rknn/3sZ1myZAmPPvoo++yzD8OGDePjH/84gwcP5sYbb9xoXxMmTOCss87iueeeY+jQodx666185jOf6Y5f41arK7Azc3l1+2xE3AGMB56JiJFV73ok8OxmnnstcC3AuHHjNv9WRZL6sWa8IX311VcZNWrUhuVzzjmnruedfvrpLF26lIMOOojMZPjw4dx5552cfPLJHHPMMYwbN46xY8eyzz771LW/kSNHctJJJ3HVVVdx4YUXcvHFF3PkkUfyxhtv0NLSwlVXXcXEiRM5//zzmTBhArvuuiv77bffm4av17vwwgv53Oc+x5gxY8hMWltbueeee5g5cya33HILLS0tvP3tb+eiiy5i7ty5nHvuuWyzzTa0tLRw9dVXv6m2Sy65hMMOO4zM5AMf+ABTpkypq13dLbbU3QeIiO2BbTLzler+fcA/AocDqzLz0og4DxiWmV/Y0r7GjRuX62fdSWAPW/3XokWL2HfffZtdRlFWr17N4MGDWbduHccddxynnnoqxx13XLPL2qL2jnNEzG8zgbtu9fSwdwHuqMbpBwL/kpn3RsRc4AcRcRrwR+CELexDkqQumTFjBrNmzWLt2rUceeSRG2aW9xcdBnZmLgEOaGf9Kmq9bEmSGm7958P7K690JklN0tEpSZWtu4+vgS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t/fTyWeJ1HqdLquP0SHWc9ml2zV1sTwCXA78Ffg2c2NE+vTSpJEkF6KtD4pIk9SkGtiRJBTCwJUkqgIEtSVIBDGxJkgpgYEuSVAADW5KkAvx/kFpX7u7SNrMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差分布，是否符合模型假设，噪声为0为高斯分布\n",
    "f, ax = plt.subplots(figsize=(7,5))\n",
    "f.tight_layout()\n",
    "# y_train-y_train_pre 残差\n",
    "ax.hist(y_train-y_train_pre,bins = 40,label = 'LinearRegression',color = 'b',alpha = 0.5)\n",
    "ax.set_title(\"Histogram of Rss\")\n",
    "ax.legend(loc = 'best')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAch0lEQVR4nO3deXxUVZr/8c+TkJAg0WAEFWRtcQcCBhFBfoiIgXZhs5sm0IOIoRlRQEcbldc4QGuLqAMiIyMubdugdsumIoKibEI0wQBBWdTGKIsjICBLIEs9vz+qQkcMSWW5OVWV5/161Yu6lZt7vkB4uPece88RVcUYY7wQ5TqAMSZyWYExxnjGCowxxjNWYIwxnrECY4zxTB3XASrinHPO0RYtWriOYYw5xfr16/epasNTPw+rAtOiRQuysrJcxzDGnEJEckv73C6RjDGesQJjjPGMFRhjjGecFRgRiRORT0Vko4h8LiITXWUxxnjDZSfvCaCHqh4RkRhgjYgsUdUMh5mMMdXI2RmM+h0JbMYEXvbkpTGOHThwgPvuu4+jR49W+V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qxvtDPeEJEkYHlg8zygCNgb2L4q8AxRTWdaCgwMPKdjwoQNU5syich/AUdU9clTPhf8Pz++Ur+x+tqvkXaMN+wSyQRNRC4MPNM0C/gMaCoiB0t8fZCIvBB4f66IzBeRrMDcIleXcrwRgflxlgbmh5lwmnbOF5GdJe4uvT0wt85GEXk52PZMzbNLJFNRlwG3q+ofRKSsn59ngCdUNSPwdPA7QGkPzF0V+DwfyBSRd4AjJdsB8J/IgIi0w//YxTWq+qOInF3B9kwNsgJjKuprVc0MYr+ewMXFhQFoICLxqpp3yn5LVfUAgIgsBLoC75XRTg/gDVX9EaD41wq0Z2qQFRhTUUdLvPfx8+kX4kq8F4LrED61E7B4++ipO5Y4bmkdh8G2Z2qQ9cGYSgt0vB4QkdYiEgX0K/HlD4C7ijdEJPk0h+klIokiUg//zHYfl9PsB8Cg4kujEpdIwbZnapAVGFNVf8R/SbMc/1wvxe4CugQ6Y78A7jzN96/BP19PNvCaqm4oqzFV3QQ8AawKzLg2tYLtmRpkw9TGGREZAVyhqmNdZzHesDMYY4xn7AzGGOMZO4MxxnjGCowxxjNWYIwxnrECY4zxjBUYY4xn/j+Hx7/pzh46cAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#观察预测值与真值散点图\n",
    "plt.figure(figsize=(4,3))\n",
    "plt.scatter(y_train,y_train_pre)\n",
    "plt.plot([-3,3],[-3,3],'--k')\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True price')\n",
    "plt.ylabel('pre price')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r2 test 0.6839491283767416\n",
      "r2 train 0.7513469187744316\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import RidgeCV\n",
    "\n",
    "#设置超参数搜索范围\n",
    "alphas = [0.01,0.1,1,10,100]\n",
    "#生成实例\n",
    "ridge = RidgeCV(alphas = alphas, store_cv_values = True)\n",
    "ridge.fit(x_train,y_train)\n",
    "y_test_pre_ridge = ridge.predict(x_test)\n",
    "y_train_pre_ridge = ridge.predict(x_train)\n",
    "print(\"r2 test\",r2_score(y_test,y_test_pre_ridge))\n",
    "print('r2 train',r2_score(y_train,y_train_pre_ridge))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEGCAYAAABy53LJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deZgc9X3n8fd3Tml0jY7RNSMhAQIsQEhiJGGDsc1lYWxEMBgdTkjWCQ+78MRZP84arx37WXb95LG96zyP1yQ2SYiTzYzEZYOMwYABGxNbI43uA4SEQK3R6Bjd55z93T+6Wmo1c/RIU1PdPZ/X8/Qz1VW/qvpWSZqPqn51mLsjIiKSqYKoCxARkdyi4BARkV5RcIiISK8oOEREpFcUHCIi0itFURfQH8aMGeNTpkyJugwRkZyyevXqA+5ekT5+QATHlClTqK+vj7oMEZGcYmY7Oxsf6qkqM5tvZlvNbLuZPdLJ9AfNbKOZrTOzt8xsejB+tJm9YWYnzOxHafP8JljmuuAzNsxtEBGRc4V2xGFmhcBjwK1AA7DKzJa7+5aUZrXu/uOg/Z3AD4D5QDPwN8BVwSfdEnfXIYSISATCPOKYC2x39x3u3gosAxakNnD3YylfhwAejD/p7m+RCBAREckiYQZHJbAr5XtDMO4cZvaQmb0HfA/4ywyX/S/Baaq/MTPrrIGZPWBm9WZW39TU1NvaRUSkC2EGR2e/0D/0YCx3f8zdLwG+Bnwzg+Uuc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8n0X+xnsRRwH9z971m9ixwM4lf0O+SePPa0WCeX5IIkl+7+3ozW0vi6ak7gP/oYj0ngSvNbHWwnPt6qOvvgWfN7F4ST689mTLtU0ENIn1KT8cVuUBmNtQTb30bTeIo5PogVAaT+GV+fdA3ksmyTrj70D6q601ggbsf7ovliSTpiEPkwr1gZuVACfA/3X0vgLufNrNvk3i3c6w/CwpOp/1AoSFh0BGHiIj0ijrHRUSkVxQcIiLSKwoOERHpFQWHiIj0ioJDRER65f8DLXJ8Wz2Ok8EAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is 1.0\n"
     ]
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_,axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1))\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "print('alpha is',ridge.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>RM</td>\n",
       "      <td>0.437204</td>\n",
       "      <td>0.434427</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ZN</td>\n",
       "      <td>0.122593</td>\n",
       "      <td>0.119276</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.094125</td>\n",
       "      <td>0.090785</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.065403</td>\n",
       "      <td>0.065826</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.034324</td>\n",
       "      <td>0.035178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.033908</td>\n",
       "      <td>0.032990</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030563</td>\n",
       "      <td>0.030898</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.012456</td>\n",
       "      <td>0.010157</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.003638</td>\n",
       "      <td>0.003634</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008870</td>\n",
       "      <td>-0.008772</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011838</td>\n",
       "      <td>-0.011527</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040752</td>\n",
       "      <td>-0.038830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.051096</td>\n",
       "      <td>-0.050776</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.080363</td>\n",
       "      <td>-0.079947</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.110471</td>\n",
       "      <td>-0.107342</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.166505</td>\n",
       "      <td>-0.160655</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.188093</td>\n",
       "      <td>-0.187669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.245829</td>\n",
       "      <td>-0.235899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.383894</td>\n",
       "      <td>-0.372376</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.497139</td>\n",
       "      <td>-0.494779</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns   coef_lr  coef_ridge\n",
       "5        RM  0.437204    0.434427\n",
       "1       ZN   0.122593    0.119276\n",
       "19   RAD_24  0.094125    0.090785\n",
       "3      CHAS  0.065403    0.065826\n",
       "13    RAD_3  0.034324    0.035178\n",
       "17    RAD_7  0.033908    0.032990\n",
       "18    RAD_8  0.030563    0.030898\n",
       "2    INDUS   0.012456    0.010157\n",
       "6       AGE  0.003638    0.003634\n",
       "14    RAD_4 -0.008870   -0.008772\n",
       "15    RAD_5 -0.011838   -0.011527\n",
       "12    RAD_2 -0.040752   -0.038830\n",
       "16    RAD_6 -0.051096   -0.050776\n",
       "11    RAD_1 -0.080363   -0.079947\n",
       "8       TAX -0.110471   -0.107342\n",
       "4       NOX -0.166505   -0.160655\n",
       "9   PTRATIO -0.188093   -0.187669\n",
       "0      CRIM -0.245829   -0.235899\n",
       "7       DIS -0.383894   -0.372376\n",
       "10    LSTAT -0.497139   -0.494779"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fs = pd.DataFrame({\"columns\":list(feat_names),\"coef_lr\":list((lr.coef_.T)),\"coef_ridge\":list((ridge.coef_.T))})\n",
    "fs.sort_values(by = ['coef_lr'],ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "#发现ridge对系数有收缩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "r2 test 0.6822664578423105\n",
      "r2 train 0.7513817157551513\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/jay/opt/anaconda3/lib/python3.7/site-packages/sklearn/model_selection/_split.py:1978: FutureWarning: The default value of cv will change from 3 to 5 in version 0.22. Specify it explicitly to silence this warning.\n",
      "  warnings.warn(CV_WARNING, FutureWarning)\n"
     ]
    }
   ],
   "source": [
    "#Lasso  L1正则\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#使用默认的alpha\n",
    "lasso = LassoCV()\n",
    "lasso.fit(x_train,y_train)\n",
    "y_test_pre_lasso = lasso.predict(x_test)\n",
    "y_train_pre_lasso = lasso.predict(x_train)\n",
    "print(\"r2 test\",r2_score(y_test,y_test_pre_lasso))\n",
    "print('r2 train',r2_score(y_train,y_train_pre_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEGCAYA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MbOvEP5O6iMTWVAwnPZPCg2JBx1xiIhITHRyXEREYqLgEBGRmCg4REQkJgoOERGJiYJDRERi8v8BY4rv697VSioAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is 3.0853701706804334e-05\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_,axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses)\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "print('alpha is',lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>columns</th>\n",
       "      <th>coef_lr</th>\n",
       "      <th>coef_ridge</th>\n",
       "      <th>coef_lasso</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>RM</td>\n",
       "      <td>0.437204</td>\n",
       "      <td>0.434427</td>\n",
       "      <td>0.437759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>ZN</td>\n",
       "      <td>0.122593</td>\n",
       "      <td>0.119276</td>\n",
       "      <td>0.119642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>19</td>\n",
       "      <td>RAD_24</td>\n",
       "      <td>0.094125</td>\n",
       "      <td>0.090785</td>\n",
       "      <td>0.098669</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>CHAS</td>\n",
       "      <td>0.065403</td>\n",
       "      <td>0.065826</td>\n",
       "      <td>0.065676</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>13</td>\n",
       "      <td>RAD_3</td>\n",
       "      <td>0.034324</td>\n",
       "      <td>0.035178</td>\n",
       "      <td>0.043230</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>17</td>\n",
       "      <td>RAD_7</td>\n",
       "      <td>0.033908</td>\n",
       "      <td>0.032990</td>\n",
       "      <td>0.041340</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>18</td>\n",
       "      <td>RAD_8</td>\n",
       "      <td>0.030563</td>\n",
       "      <td>0.030898</td>\n",
       "      <td>0.038579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>INDUS</td>\n",
       "      <td>0.012456</td>\n",
       "      <td>0.010157</td>\n",
       "      <td>0.007918</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>AGE</td>\n",
       "      <td>0.003638</td>\n",
       "      <td>0.003634</td>\n",
       "      <td>0.002051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>14</td>\n",
       "      <td>RAD_4</td>\n",
       "      <td>-0.008870</td>\n",
       "      <td>-0.008772</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>15</td>\n",
       "      <td>RAD_5</td>\n",
       "      <td>-0.011838</td>\n",
       "      <td>-0.011527</td>\n",
       "      <td>-0.002920</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>12</td>\n",
       "      <td>RAD_2</td>\n",
       "      <td>-0.040752</td>\n",
       "      <td>-0.038830</td>\n",
       "      <td>-0.029788</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>16</td>\n",
       "      <td>RAD_6</td>\n",
       "      <td>-0.051096</td>\n",
       "      <td>-0.050776</td>\n",
       "      <td>-0.042225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>11</td>\n",
       "      <td>RAD_1</td>\n",
       "      <td>-0.080363</td>\n",
       "      <td>-0.079947</td>\n",
       "      <td>-0.070521</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>TAX</td>\n",
       "      <td>-0.110471</td>\n",
       "      <td>-0.107342</td>\n",
       "      <td>-0.105024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>NOX</td>\n",
       "      <td>-0.166505</td>\n",
       "      <td>-0.160655</td>\n",
       "      <td>-0.161419</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>9</td>\n",
       "      <td>PTRATIO</td>\n",
       "      <td>-0.188093</td>\n",
       "      <td>-0.187669</td>\n",
       "      <td>-0.186704</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>CRIM</td>\n",
       "      <td>-0.245829</td>\n",
       "      <td>-0.235899</td>\n",
       "      <td>-0.239578</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>DIS</td>\n",
       "      <td>-0.383894</td>\n",
       "      <td>-0.372376</td>\n",
       "      <td>-0.379549</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>10</td>\n",
       "      <td>LSTAT</td>\n",
       "      <td>-0.497139</td>\n",
       "      <td>-0.494779</td>\n",
       "      <td>-0.496427</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    columns   coef_lr  coef_ridge  coef_lasso\n",
       "5        RM  0.437204    0.434427    0.437759\n",
       "1       ZN   0.122593    0.119276    0.119642\n",
       "19   RAD_24  0.094125    0.090785    0.098669\n",
       "3      CHAS  0.065403    0.065826    0.065676\n",
       "13    RAD_3  0.034324    0.035178    0.043230\n",
       "17    RAD_7  0.033908    0.032990    0.041340\n",
       "18    RAD_8  0.030563    0.030898    0.038579\n",
       "2    INDUS   0.012456    0.010157    0.007918\n",
       "6       AGE  0.003638    0.003634    0.002051\n",
       "14    RAD_4 -0.008870   -0.008772   -0.000000\n",
       "15    RAD_5 -0.011838   -0.011527   -0.002920\n",
       "12    RAD_2 -0.040752   -0.038830   -0.029788\n",
       "16    RAD_6 -0.051096   -0.050776   -0.042225\n",
       "11    RAD_1 -0.080363   -0.079947   -0.070521\n",
       "8       TAX -0.110471   -0.107342   -0.105024\n",
       "4       NOX -0.166505   -0.160655   -0.161419\n",
       "9   PTRATIO -0.188093   -0.187669   -0.186704\n",
       "0      CRIM -0.245829   -0.235899   -0.239578\n",
       "7       DIS -0.383894   -0.372376   -0.379549\n",
       "10    LSTAT -0.497139   -0.494779   -0.496427"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fs = pd.DataFrame({\"columns\":list(feat_names),\"coef_lr\":list((lr.coef_.T)),\"coef_ridge\":list((ridge.coef_.T)),\"coef_lasso\":list((lasso.coef_.T))})\n",
    "fs.sort_values(by = ['coef_lr'],ascending = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
